﻿using System;
using System.Windows;
using Chambills.Present.Core;
using Present.Commands.Async.Actions.Decorators;

namespace Present.Commands.Async.Actions
{
    public static class AsyncCommandTargetExtensions
    {
        public static ObservableAsyncActionDecorator<TParameter, TResult> ToObservable<TParameter, TResult>(this IAsyncAction<TParameter, TResult> me)
        {
            return new ObservableAsyncActionDecorator<TParameter, TResult>(me);
        }

        public static SuccessVisualStateTransitionActionDecorator<TParameter, TResult> SuccessVisualState<TParameter, TResult>(this IAsyncAction<TParameter, TResult> me, string state, Action<TResult> afterTransistion)
        {
            return new SuccessVisualStateTransitionActionDecorator<TParameter, TResult>(me, Application.Current.Dispatcher, new PresentVisualStateManager(), new ViewRegistry(), null, state, afterTransistion);
        }

        public static SuccessVisualStateTransitionActionDecorator<TParameter, TResult> SuccessVisualState<TParameter, TResult>(this IAsyncAction<TParameter, TResult> me, IViewModel viewModel, string state, Action<TResult> afterTransistion)
        {
            return new SuccessVisualStateTransitionActionDecorator<TParameter, TResult>(me, Application.Current.Dispatcher, new PresentVisualStateManager(), new ViewRegistry(), viewModel, state, afterTransistion);
        }

        public static SuccessVisualStateTransitionActionDecorator<TParameter, TResult> SuccessVisualState<TParameter, TResult>(this IAsyncAction<TParameter, TResult> me, IViewModel viewModel, string state)
        {
            return me.SuccessVisualState(viewModel, state, r => { });
        }

        public static SuccessVisualStateTransitionActionDecorator<TParameter, TResult> SuccessVisualState<TParameter, TResult>(this IAsyncAction<TParameter, TResult> me,  string state)
        {
            return me.SuccessVisualState(null, state, r => { });
        }
    }
}